package com.wwwzh.himalayafm.adapter.recommend;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.squareup.picasso.Picasso;
import com.wwwzh.himalayafm.R;
import com.wwwzh.himalayafm.callback.OnImageClickListener;
import com.wwwzh.himalayafm.entity.recommend.RecommendGuessItem;

import java.util.List;

/**
 * Created by weizz on 2016/12/8.
 */

public class GuessItemAdapter extends RecyclerView.Adapter<GuessItemAdapter.GuessItemViewHolder> {


    private Context context;
    private LayoutInflater inflater;
    private List<RecommendGuessItem> list;
    private static OnImageClickListener gListener;

    public GuessItemAdapter(Context context, List<RecommendGuessItem> gList) {
        this.context = context;
        this.inflater = LayoutInflater.from(context);
        this.list = gList;
    }

     public static void setOnImageClickListener(OnImageClickListener listener) {
         gListener = listener;
     }
    @Override
    public GuessItemViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new GuessItemViewHolder(inflater.inflate(R.layout.layout_recomm_guessitem,parent,false));
    }

    @Override
    public void onBindViewHolder(GuessItemViewHolder holder, final int position) {
        holder.imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (gListener!=null){
                    gListener.onImageClick(position+"");
                }
            }
        });
        Picasso.with(context).load(list.get(position).getCoverSmall()).into(holder.imageView);
        holder.titleView.setText(list.get(position).getTitle());
        if (list.get(position).getTags().equals("")) {
            holder.tagView.setVisibility(View.INVISIBLE);
        }else{
            holder.tagView.setText(list.get(position).getTags());
        }
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    public static  class GuessItemViewHolder extends RecyclerView.ViewHolder {

        private ImageView imageView;
        private TextView titleView;
        private TextView tagView;
        public GuessItemViewHolder(View itemView) {
            super(itemView);
            this.imageView = (ImageView) itemView.findViewById(R.id.guess_imageView);
            this.titleView = (TextView) itemView.findViewById(R.id.guess_title);
            this.tagView = (TextView) itemView.findViewById(R.id.guess_tag);

        }
    }


}
